package cc.sheji.reposity;


import cc.sheji.domain.User;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface UserRepository extends CrudRepository<User, Long> , JpaSpecificationExecutor<User> {

    public User findUserByName(String name);
    public User findFirstByPhone(String phone);
    @Modifying
    @Query(value = "update User set   vipNum0 =3 ")
    public void updateAll();


    @Modifying
    @Query(value = "update User set   todaySignIn =0 ")
    public void updateTodaySignAll();

    @Modifying
    @Query(value = "update user set   sign_in_day =0 where  sign_time<= DATE_SUB( NOW(), INTERVAL 1 DAY ) " ,nativeQuery = true)
    public void updateAll1();

    List<User> findAllByVip1TimeLessThan(Date date);

    @Query("select  count (id)  from User where vip1!=0 or vip2!=0 or vip3!=0 or vip4!=0   ")
    Long vipNum();

    /**
     * 根据验证呀查找是否已经存在了，存在了则重新生成
     * @param code
     * @return
     */
    User findFirstByInvitationCode(String code);

}
